package reflectx

import (
	"gitee.com/zhongguo168a/gocodes/datax/schemax"
)

type EnumDeclRef struct {
}

func (desc *EnumDeclRef) RefNew() IRefObject {
	return &schemax.EnumDecl{}
}

func (desc *EnumDeclRef) RefType() string {
	return "enumdecl"
}

func (desc *EnumDeclRef) RefHas(field string) bool {
	switch field {
	case "Name":
		return true
	case "Kind":
		return true
	case "Namespace":
		return true
	case "Fields":
		return true
	}
	return false
}

func (desc *EnumDeclRef) RefGet(target IRefObject, key string) (interface{}, bool) {
	obj := target.(*schemax.EnumDecl)
	switch key {
	case "Name":
		return obj.Name, false
	case "Kind":
		return obj.Kind, false
	case "Namespace":
		return obj.Namespace, false
	case "Fields":
		return obj.Fields, false
	}
	return nil, true
}
func (desc *EnumDeclRef) RefSet(target IRefObject, key string, val interface{}) {
	obj := target.(*schemax.EnumDecl)
	switch key {
	case "Name":
		obj.Name = val.(string)
	case "Kind":
		obj.Kind = val.(int)
	case "Namespace":
		obj.Namespace = val.(string)
	case "Fields":
		obj.Fields = val.([]*schemax.Field)
	}
	return
}
func (desc *EnumDeclRef) RefSliceLength(target IRefObject, key string) int {
	obj := target.(*schemax.EnumDecl)
	switch key {
	case "Fields":
		return len(obj.Fields)
	}
	return 0
}

func (desc *EnumDeclRef) RefSliceGet(target IRefObject, key string, index int) (interface{}, bool) {
	obj := target.(*schemax.EnumDecl)
	switch key {
	case "Fields":
		val := obj.Fields[index]
		return val, val == nil
	}
	return nil, true
}
func (desc *EnumDeclRef) RefSliceSet(target IRefObject, key string, index int, val interface{}) {
	obj := target.(*schemax.EnumDecl)
	switch key {
	case "Fields":
		obj.Fields[index] = val.(*schemax.Field)
	}
	return
}

func (desc *EnumDeclRef) RefSliceNew(field string, len int, cap int) interface{} {

	switch field {
	case "Fields":
		return make([]*schemax.Field, len, cap)
	}
	return nil
}
